package com.yd;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by john on 16/3/9.
 */
public class GamePlayer implements Player {

    public static final float COUNT_TEN = 10.5f;    // 十点半
    private String name;
    private int bet;
    private List<Card> cards = new ArrayList<Card>(5);
    private float count;
    private int status = STATUS_NORMAL;

    public GamePlayer(String name) {
        this.name = name;
    }

    public void bet(int bet) {
        this.bet = bet;
    }

    public int getBet() {
        return bet;
    }

    public List<Card> getCards() {
        return cards;
    }

    public void addCard(Card card) {
        if (card == null) {
            throw new IllegalArgumentException("参数不能为空.");
        }
        if (status == STATUS_TEN) {
            throw new IllegalStateException("已经十点半了, 不能再要牌了.");
        }
        if (status == STATUS_FIVE) {
            throw new IllegalStateException("已经五龙, 不能再要牌了.");
        }

        count += card.getCount();
        cards.add(card);

        if (count > COUNT_TEN) {
            // 大于十点半爆表
            status = STATUS_OVER;
        } else if (cards.size() == 5) {
            // 五张, 五龙
            status = STATUS_FIVE;
        } else if (count == COUNT_TEN) {
            // 十点半
            status = STATUS_TEN;
        }
    }

    public float getCount() {
        return count;
    }

    public int getStatus() {
        return status;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String toString() {
        return "GamePlayer{" +
                "name='" + name + '\'' +
                '}';
    }
}
